<?php
	//统一价格
	if($_POST['act']=='price')
	{
		if($_POST['type']==1)
		{
			$id=explode(',',substr($_POST['id'],0,-1));
			if(!empty($_POST['price1']))
			{
				foreach($id as $list)
				{
					$sql="UPDATE ".PRO." SET `$_POST[name]` = '$_POST[price1]'  WHERE id='$list' ";
					$db->query($sql);
					$sql="select id from ".SETMEAL." where pid=$list";
					$db->query($sql);
					$sid=$db->fetchField('id');
					if($sid)
					{
						$sql="UPDATE ".SETMEAL." SET `$_POST[name]` = '$_POST[price1]'  WHERE pid='$list' ";
						$db->query($sql);	
					}
				}
			}
		}
		else
		{
			$id=explode(',',substr($_POST['id'],0,-1));
			if(!empty($_POST['price2']))
			{
				foreach($id as $list)
				{
					$sql="UPDATE ".PRO." SET `$_POST[name1]` = `$_POST[name2]` $_POST[fun] '$_POST[price2]'  WHERE id='$list' ";
					
					$db->query($sql);
					$sql="select id from ".SETMEAL." where pid=$list";
					$db->query($sql);
					$sid=$db->fetchField('id');
					if($sid)
					{
						$sql="UPDATE ".SETMEAL." SET `$_POST[name1]` = `$_POST[name2]` $_POST[fun] '$_POST[price2]' WHERE pid='$list' ";
						$db->query($sql);	
					}
				}
			}
		}
		die;
	}
	//统一更新限购数量
	if($_POST['act']=='limit')
	{
			$ids=substr($_POST['id'],0,-1);
			if((!empty($_POST['buy_limit_nums_1']))&&$_POST['type']==1)
			{
				$sql="UPDATE ".SETMEAL." SET `buy_limit` = '$_POST[buy_limit_nums_1]'  WHERE pid in ({$ids}) ";
				$db->query($sql);	
			}elseif((!empty($_POST['buy_limit_nums_2']))&&$_POST['type']==2){
				$sql="UPDATE ".SETMEAL." SET `buy_limit` = `buy_limit` $_POST[fun] $_POST[buy_limit_nums_2]  WHERE pid in ({$ids}) ";
				$db->query($sql);
			}
			echo "<script type='text/javascript'>window.parent.main.document.location.reload();window.parent.DialogManager.close('unify');</script>";
		die;
	}
	
	if ($_GET['type']=='skuop'){
	    $sql="select property_id,id from ".PRO." where id=$_GET[id] limit 1";
	    $db->query($sql);
	    $product_info=$db->fetchRow();
	    
	    
	    
	    include_once("$config[webroot]/module/product/includes/plugin_add_field_class.php");
	    $addfield = new AddField('product');
	    $extfiled=$addfield->addfieldinput($_GET['edit'],'haiou_defind_'.$product_info['property_id']);//
	    //print_r($extfiled);
	}
	
	$tpl->assign("config",$config);
	$tpl->display("product_unify.htm");
	
?>